<template>
  <div id="app">
    <!-- <div id="nav">
      <router-link to="/">Home</router-link> |
      <router-link to="/test">Test</router-link> |
      <router-link to="/login">Login</router-link> |
      <router-link to="/about">About</router-link>
    </div> -->
    <el-container>
      <el-header style="font-size: 1.5em">
        <div style="float: left">{{ workTitle }}</div>
        <el-dropdown
          class="dropdown"
          style="font-size: 1em"
          @command="itemClick"
        >
          <i class="el-icon-setting" style="margin-right: 15px"></i>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="1">opt1</el-dropdown-item>
            <el-dropdown-item command="2">opt2</el-dropdown-item>
            <el-dropdown-item command="3">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
        <span>{{ this.$store.state.userData.name }}</span>
      </el-header>
      <el-container>
        <el-aside width="280px">
          <el-menu
            router
            active="$route.path"
            class="el-menu-vertical-demo"
            unique-opened
            v-if="this.$store.state.login"
          >
            <el-menu-item index="/">
              <i class="el-icon-house"></i>
              <span slot="title">主页</span>
            </el-menu-item>

            <el-submenu index="1">
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>销售机会管理</span>
              </template>
              <el-menu-item index="/xsjh/create"
                ><i class="el-icon-document-add"></i>创建</el-menu-item
              >
              <el-menu-item index="/xsjh/list"
                ><i class="el-icon-s-order"></i>浏览</el-menu-item
              >
            </el-submenu>
            <el-submenu
              index="3"
              v-if="this.$store.state.userPower.power == 'AM'"
            >
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>开发计划管理</span>
              </template>
              <el-menu-item index="/kfjh/create"
                ><i class="el-icon-document-add"></i>制定计划</el-menu-item
              >
              <el-menu-item index="/kfjh/list"
                ><i class="el-icon-s-order"></i>计划一览</el-menu-item
              >
            </el-submenu>

            <el-submenu
              index="4"
              v-if="this.$store.state.userPower.power == 'AM'"
            >
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>客户信息与联系人</span>
              </template>
              <!-- <el-menu-item index="/khxx/create"
                ><i class="el-icon-document-add"></i>新增客户</el-menu-item
              > -->
              <el-menu-item index="/khxx/list"
                ><i class="el-icon-s-order"></i>查看客户信息</el-menu-item
              >
              <el-menu-item index="/khxx/listLXR"
                ><i class="el-icon-s-order"></i>查看联系人信息</el-menu-item
              >
              <el-menu-item index="/khxx/listDSJ"
                ><i class="el-icon-s-order"></i>查看大事件</el-menu-item
              >
            </el-submenu>
            <el-submenu
              index="5"
              v-if="this.$store.state.userPower.power == 'AM'"
            >
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>订单管理</span>
              </template>
              <!-- <el-menu-item index="/lsdd/create"
                ><i class="el-icon-document-add"></i>添加订单</el-menu-item
              > -->
              <el-menu-item index="/lsdd/list"
                ><i class="el-icon-s-order"></i>浏览订单</el-menu-item
              >
            </el-submenu>
            <el-submenu
              index="6"
              v-if="this.$store.state.userPower.power == 'AM'"
            >
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>客户流失</span>
              </template>
              <el-menu-item index="/khls/list"
                ><i class="el-icon-s-order"></i>客户流失一览</el-menu-item
              >
            </el-submenu>
            <el-submenu index="7">
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>客户服务</span>
              </template>
              <el-menu-item
                index="/khfw/create"
                v-if="this.$store.state.userPower.power == 'AM'"
                ><i class="el-icon-document-add"></i>添加客户服务</el-menu-item
              >
              <el-menu-item index="/khfw/list"
                ><i class="el-icon-s-order"></i>浏览客户服务</el-menu-item
              >
            </el-submenu>
            <el-submenu
              index="8"
              v-if="this.$store.state.userPower.power != 'SE'"
            >
              <template slot="title">
                <i class="el-icon-s-marketing"></i>
                <span>报表</span>
              </template>
              <el-menu-item index="/tjbb/tjdd">订单</el-menu-item>
              <el-menu-item index="/tjbb/khsl">客户</el-menu-item>
              <el-menu-item index="/tjbb/khls">流失</el-menu-item>
              <el-menu-item index="/tjbb/khfw">客户服务</el-menu-item>
            </el-submenu>

            <el-menu-item index="100">
              <i class="el-icon-setting"></i>
              <span slot="title">导航壹佰</span>
            </el-menu-item>
          </el-menu>
          <el-menu
            router
            active="$route.path"
            class="el-menu-vertical-demo"
            unique-opened
            v-if="!this.$store.state.login"
          >
            <el-menu-item index="/login">
              <i class="el-icon-setting"></i>
              <span slot="title">登录</span>
            </el-menu-item>
          </el-menu>
        </el-aside>
        <el-container>
          <el-main>
            <router-view />
          </el-main>
          <el-footer>权限:{{ this.$store.state.userPower.power }}</el-footer>
        </el-container>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data() {
    return {
      workTitle: "CRM管理系统",
    };
  },
  methods: {
    itemClick(cmd) {
      this.$message(cmd);
      switch (cmd) {
        // case "1":
        //   this.$store.commit("userPower", {power: "AM"});
        //   break;
        case "3":
          if (this.$cookies.isKey("user")) {
            this.$cookies.remove("user");
            this.$router.go(0);
          }
          break;

        default:
          break;
      }
    },
  },
  created: function () {
    // if (this.$store.state.init && window.location.href.indexOf("login") == -1){
    //   this.$store.commit("init");
    //   this.$router.replace({ path: "/login" });
    // }
    if (this.$store.state.login == false) {
      if (window.location.href.indexOf("login") == -1) {
        this.$router.replace({ path: "/login" });
      }
    } else {
      if (window.location.href.indexOf("login") != -1) {
        this.$router.replace({ path: "/" });
      }
    }
  },
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

#nav {
  padding: 30px;
}

#nav a {
  font-weight: bold;
  color: #2c3e50;
}

#nav a.router-link-exact-active {
  color: #42b983;
}

span {
  user-select: none;
}
.dropdown .el-icon-setting {
  transition: color 1s;
}
.el-icon-setting:hover {
  color: rgb(0, 153, 255);
}
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: right;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  /* line-height: 160px; */
}

#app > .el-container {
  margin-bottom: 40px;
}
#app > .el-container > .el-container {
  height: calc(100vh - 110px);
}
</style>
